//
//  NRWBuyCarFilterHeader.m
//  NRWMall
//
//  Created by 邢毅 on 2018/6/11.
//  Copyright © 2018年 com.anpxd. All rights reserved.
//

#import "NRWBuyCarFilterHeader.h"

@interface CustomerLayer : CALayer

@end

@implementation CustomerLayer
- (CGFloat)zPosition {
    return 0;
}
@end

@implementation NRWBuyCarFilterHeader
{
    CALayer *_mLineLayer; /**< 橙色线 */
    CALayer *_mMinLineLayer; /**< 灰色分割线 */
    UILabel *_mTitleLabel; /**< 标题label */
    UILabel *_mDetailLabel; /**< 选项label */
}

- (void)setTitleStr:(NSString *)titleStr {
    
    _titleStr = titleStr;
    
    _mTitleLabel.text = titleStr;
    
    [self setNeedsLayout];
}

- (void)setDetailStr:(NSString *)detailStr {
    
    _detailStr = detailStr;
    
    _mDetailLabel.text = detailStr;
    
    [self setNeedsLayout];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setupUI];
    }
    return self;
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    _mLineLayer.frame = CGRectMake(0, 0, 1.5, self.viewHeight);
    
    [_mTitleLabel sizeToFit];
    _mTitleLabel.frame = CGRectMake(14, 0, _mTitleLabel.viewWidth, self.viewHeight);
    
    _mMinLineLayer.frame = CGRectMake(_mTitleLabel.viewMaxX + 10, self.viewHeight / 4, 0.5, self.viewHeight / 2);
    
    _mDetailLabel.frame = CGRectMake(CGRectGetMaxX(_mMinLineLayer.frame) + 10, 0, SCREEN_WIDTH() - CGRectGetMaxX(_mMinLineLayer.frame) - 10 - 14, self.viewHeight);
}

- (void)setupUI {
    
    _mLineLayer = [[CALayer alloc] init];
    _mLineLayer.backgroundColor = mainColor().CGColor;
    _mLineLayer.opaque = YES;
    [self.layer addSublayer:_mLineLayer];
    
    _mMinLineLayer = [[CALayer alloc] init];
    _mMinLineLayer.backgroundColor = getColor(@"cccccc").CGColor;
    _mMinLineLayer.opaque = YES;
    [self.layer addSublayer:_mMinLineLayer];
    
    _mTitleLabel = [[UILabel alloc] init];
    _mTitleLabel.textColor = mainFontColor();
    _mTitleLabel.font = getThemeFont(13);
    _mTitleLabel.backgroundColor = getColor(@"#F9F9F9");;
    _mTitleLabel.opaque = YES;
    [self addSubview:_mTitleLabel];
    
    _mDetailLabel = [[UILabel alloc] init];
    _mDetailLabel.textColor = mainColor();
    _mDetailLabel.font = getThemeFont(13);
    _mDetailLabel.backgroundColor = getColor(@"#F9F9F9");
    _mDetailLabel.opaque = YES;
    [self addSubview:_mDetailLabel];
}

+ (Class)layerClass {
    return [CustomerLayer class];
}

@end
